﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Condimar.Entities;
using System.Data;

namespace Condimar.Repository
{
    public class ComDAO: MasterRepository, ICompraDAO
    {
        public List<Compra> GetAllFromCompras()
        {
            throw new NotImplementedException();
        }

        public List<Compra> GetFromCompraByProveedor(string proveedor)
        {
            throw new NotImplementedException();
        }

        public Compra GetFromCompraById(int id)
        {
            var query = from c in Context.Compras
                        .Include("Proveedor")
                        .Include("DetalleCompra.Producto")
                        where c.Id.Equals(id)
                        select c;
            return query.SingleOrDefault();
        }

        public void AddCompra(Compra compra)
        {
            foreach (var item in compra.DetalleCompras)
            {
                Context.Entry(item.Producto).State = EntityState.Unchanged;
                Context.Entry(item).State = EntityState.Added;
            }

            Context.Entry(compra.Proveedor).State = EntityState.Unchanged;

            Context.Compras.Add(compra);
            Context.SaveChanges();
        }

        public void UpdateCompra(Compra compra)
        {
            throw new NotImplementedException();
        }

        public void RemoveCompra(int id)
        {
            throw new NotImplementedException();
        }
    }
}
